package aspect;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import db.QueryPool;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;

public class AspectGenerator {
	
	public void aspectGenerator(String message) throws ClassNotFoundException, IOException, SQLException {
		MaxentTagger tagger = new MaxentTagger("models/left3words-wsj-0-18.tagger");
		String taggedString = tagger.tagString(message);
		QueryPool query = new QueryPool();
		String[] arrays = taggedString.split(" ");
		String aspect = "";
		boolean doIt = false;
		
		for (int i = 0; i < arrays.length; i++) {
			//System.out.println(i + " / " + arrays.length + " percentage : " + ( i * 100 / arrays.length) + "%");
			doIt = true;
			if (arrays[i].indexOf("/NN") >= 0) {
				aspect = arrays[i].substring(0, arrays[i].indexOf("/NN"));
				if (aspect.length() >= 40) aspect = aspect.substring(0,40);
				if (aspect.toLowerCase().indexOf("obama") >= 0 ) doIt = false;
				if (aspect.toLowerCase().indexOf("herman") >= 0 ) doIt = false;
				if (aspect.toLowerCase().indexOf("mitt") >= 0 ) doIt = false;
				if (aspect.toLowerCase().indexOf("http:") >= 0 ) doIt = false;
				if (aspect.toLowerCase().indexOf("rt") >= 0 ) doIt = false;
				if (aspect.toLowerCase().indexOf("romney") >= 0 ) doIt = false;
				if (aspect.toLowerCase().indexOf("cain") >= 0 ) doIt = false;
				if (aspect.toLowerCase().indexOf("retweet") >= 0 ) doIt = false;
				if (aspect.toLowerCase().indexOf("barack") >= 0 ) doIt = false;
				if (aspect.toLowerCase().indexOf("rick") >= 0 ) doIt = false;
				if (aspect.toLowerCase().indexOf("perry") >= 0 ) doIt = false;
				if (doIt) {
					if (query.existAspect(aspect)) {
						query.plusOneCountOfAspects(aspect);
					} else {
						query.addNewAspect(aspect);
					}
				}

			}
		}
	}

}
